package com.qf.fmall01.controller;


import com.qf.fmall01.entity.User;
import com.qf.fmall01.service.UserService;
import com.qf.fmall01.vo.ResStatus;
import com.qf.fmall01.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("user")
@Api(value = "提供用户的登录和注册接口",tags = "用户管理")
@CrossOrigin
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "login",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("用户登录接口")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "string",name = "username", value = "用户登录账号",required = true),
            @ApiImplicitParam(dataType = "string",name = "password", value = "用户登录密码",required = true)
    })
    // 登录接口
    public ResultVO login(String username,String password){

        // 校验参数

        // 调用service层的代码进行登录逻辑处理
        ResultVO vo = userService.checkLogin(username, password);
        // 返回结果
        return vo;

    }

    @RequestMapping(value = "regist",method = RequestMethod.GET)
    @ResponseBody
    public ResultVO regist(String username,String password){

        ResultVO vo = userService.userResgit(username, password);
        return vo;
    }


}
